package entity

import (
	"shqsoft.cn/pasnj/base"
	//"strconv"
	"time"

	"github.com/jinzhu/gorm"
)

//中间业务客户认定批量
type MinOperCliePl struct {
	ID        int       `gorm:"AUTO_INCREMENT;primary_key;column:ID"`
	XH        int       `gorm:"column:XH"`             //序号
	TRTD      time.Time `gorm:"column:TRTD";type:date` //交易日期
	ITNO      string    `gorm:"column:ITNO"`           //科目号
	CHNM      string    `gorm:"column:CHNM"`           //收款名称
	HDCH      float64   `gorm:"column:HDCH"`           //金额
	KHJL1     string    `gorm:"column:KHJL1"`          //客户经理1
	JE1       float64   `gorm:"column:JE1"`            //占比1
	KHJL2     *string   `gorm:"column:KHJL2"`          //客户经理2
	JE2       *float64  `gorm:"column:JE2"`            //占比2
	KHJL3     *string   `gorm:"column:KHJL3"`          //客户经理3
	JE3       *float64  `gorm:"column:JE3";`           //占比3
	KHJL4     *string   `gorm:"column:KHJL4"`          //客户经理4
	JE4       *float64  `gorm:"column:JE4";`           //占比4
	KHJL5     *string   `gorm:"column:KHJL5"`          //客户经理5
	JE5       *float64  `gorm:"column:JE5"`            //占比5
	KHJL6     *string   `gorm:"column:KHJL6"`          //客户经理6
	JE6       *float64  `gorm:"column:JE6";`           //占比6
	KHJL7     *string   `gorm:"column:KHJL7"`          //客户经理7
	JE7       *float64  `gorm:"column:JE7";`           //占比7
	TX        int       `gorm:"column:TX";`            //条线
	TXCaption string    `gorm:"-"`
	DRJG      string    `gorm:"column:DRJG"` //导入结果
	ITEM1     string    `gorm:"column:ITEM1"`
}

//TableName 对私贷款认定分户情况
func (MinOperCliePl) TableName() string {
	return "T_MIN_OPER_CLIE_PL_DTIP"
}

func (m *MinOperCliePl) AfterFind() (err error) {
	if m.TX == 1 {
		m.TXCaption = "对公"
	} else if m.TX == 2 {
		m.TXCaption = "国际"
	} else if m.TX == 3 {
		m.TXCaption = "零售"
	} else if m.TX == 4 {
		m.TXCaption = "其他"
	} else if m.TX == 5 {
		m.TXCaption = "同业"
	} else if m.TX == 6 {
		m.TXCaption = "资金"
	} else if m.TX == 7 {
		m.TXCaption = "投行"
	}
	return nil
}

//导入时验证%
func minOperClieAfterValidation(index int, rowdatas []string) []base.ErrorData {
	return nil
}

//导入后执行分户处理
func minOperClieAfterImport(tx *gorm.DB, params map[string]string) (err error) {
	tx.Exec("exec UP_MIN_OPER_CLIE_PL")
	return nil
}

func MinOperCliePlEF() base.EntityFunc {
	return func() interface{} {
		entity := MinOperCliePl{}
		return &entity
	}
}
func MinOperCliePlESF() base.EntitiesFunc {
	return func() interface{} {
		var entities []MinOperCliePl
		return &entities
	}
}

func init() {
	base.DaoPoolObj.Put("MinOperCliePl", base.NewDefaultDao(MinOperCliePlEF(), MinOperCliePlESF(), nil))
	base.SetValidationCallBack("minOperClie", minOperClieAfterValidation)
	base.SetAfterCallBack("minOperClie", minOperClieAfterImport)
}
